/* ****************************************************************************
 * Author: 671643387
 * Date: 2015/3/17
 * ***************************************************************************/

Ext.define("sggm.view.GMPanel", {
    extend: "Ext.Panel",
    alias: "widget.gmPanel",

    id: "gmPanel",
    border: false,
    frame: false,
    title:"<h3>梦貂蝉-GM工具</h3>",
    autoScroll : true,

    //tbar: ['->',{
    //    text: "登出",
    //    action: "logout"
    //}],

    items: [{
        xtype: "form",
        id: "gmPanel.userQuery.form",
        fieldDefaults: {
            labelAlign: 'right',
            labelWidth: 70
        },
        items: [{
            layout: "column",
            frame: false,
            border: false,
            items: [{
                columnWidth:.3,
                layout: 'form',
                frame: false,
                border: false,

                items: [{
                    xtype: "textfield",
                    fieldLabel: "用户平台ID",
                    name: "openid",
                    value: (location.hash.substr(1) || "")
                }]
            }, {
                columnWidth:.3,
                layout: 'form',
                frame: false,
                border: false,
                items: [{
                    xtype: "textfield",
                    fieldLabel: "用户游戏ID",
                    name: "uid"
                }]
            }, {
                columnWidth:.3,
                layout: 'form',
                frame: false,
                border: false,
                items: [{
                    xtype: "textfield",
                    fieldLabel: "用户密码",
                    name: "key"
                }]
            }, {
                columnWidth:.1,
                layout: 'form',
                frame: false,
                border: false,
                bodyStyle: "padding-left:10px;",
                items: [{
                    xtype: "button",
                    text: "查询",
                    width: 80,
                    action: "queryUserInfo"
                }]
            }],
            bbar: ['->',{
                text: "封号",
                action: "blockUser"
            },{
                text: "解除封号",
                action: "unblockUser"
            },{
                text: "解除限制",
                action: "unblockLimitUser"
            },{
                text: "禁言",
                action: "blockUserTalk"
            },{
                text: "解除禁言",
                action: "unblockUserTalk"
            },{
                text: "清空背包",
                action: "clearUserInventory"
            },{
                text: "充值黄钻",
                action: "diamond"
            },{
                text: "查询聊天",
                action: "queryUserMessage"
            },{
                text: "一键变强",
                action: "autoStrong"
            },{
                text: "灌入角色",
                action: "setUser"
            }]
        }, { /* 玩家数据显示 */
            xtype: "gridpanel",
            title: "玩家信息",
            height: 110,

            columns: [
                {header:"OpenID", dataIndex:'openid', sortable: false},
                {header:"游戏ID", dataIndex:'uid', sortable: false},
                {header:"姓名", dataIndex:'un', sortable: false},
                {
                    header:"创建时间",
                    dataIndex:'create',
                    sortable: false,
                    renderer: renderDate,
                    width: 160
                },
                {header:"创建IP", dataIndex:'createIP', sortable: false},
                {header:"黄钻", dataIndex:'yellow', sortable: false},
                {header:"年费黄钻", dataIndex:'yellow_year', sortable: false},
                {header:"蓝钻", dataIndex:'blue', sortable: false},
                {header:"年费蓝钻", dataIndex:'blue_year', sortable: false},
                {header:"注册平台", dataIndex:'platform', sortable: false},
                {
                    header:"最后登录",
                    dataIndex:'lastActivie',
                    sortable: false,
                    renderer: renderDate,
                    width: 160
                }
            ],

            store: "UserInfo",

            bbar: ['->', {
                text: "标志数据",
                action: "updateUserMark"
            }, {
                text: "任务",
                action: "updateUserTask"
            }, {
                text: "发放物品",
                action: "sendInventory"
            }, {
                text: "发放装备",
                action: "showSendEquipWindow"
            }, {
                text: "修改武将",
                action: "updateFighter"
            }, {
                text: "发放武将",
                action: "sendFighter"
            }, {
                text: "VIP",
                action: "updateVIP"
            }, {
                text: "充值",
                action: "charge"
            }, {
                text: "合区换号",
                action: "changeRole"
            }, {
                text: "军团",
                action: "updateLeague"
            }, {
                text: "其它命令",
                action: "otherCmd"
            }, '-', {
                text: "查看JSON",
                action: "showJSON"
            }]
        }, { /* 玩家基础数据 */
            xtype: "gridpanel",
            title: "玩家基础数据",
            height: 110,

            columns: [
                {header:"经验", dataIndex:'xp', sortable: false},
                {header:"等级", dataIndex:'level', sortable: false},
                {header:"VIP", dataIndex:'vip', sortable: false, renderer: renderRed},
                {header:"金币", dataIndex:'gold', sortable: false},
                {header:"元宝", dataIndex:'cash', sortable: false, renderer: renderRed},
                {header:"粮草", dataIndex:'food', sortable: false},
                {header:"军功", dataIndex:'honor', sortable: false},
                {header:"武魂", dataIndex:'soul', sortable: false},
                {header:"战斗力", dataIndex:'fight_force', sortable: false}
            ],

            store: "UserStatus",

            buttons: [{
                xtype: "button",
                text: "单数据编辑",
                action: "editUserBasicDataSingle"
            }, {
                xtype: "button",
                text: "全数据编辑",
                action: "editUserBasicData"
            }, {
                xtype: "button",
                text: "发元宝",
                action: "basicAddCash"
            }, {
                xtype: "button",
                text: "自定义",
                action: "editCustom"
            }]

        }, { /* 标志数据 */
            xtype: "gridpanel",
            title: "标志数据",
            height: 80,

            columns: [
                {
                    header:"上次登录时间",
                    dataIndex:'day',
                    sortable: false
                },
                {header:"每日付费买粮", dataIndex:'food', sortable: false},
                {header:"每日付费买金", dataIndex:'gold', sortable: false},
                {
                    header:"在线总时长",
                    dataIndex:'online_time',
                    sortable: false,
                    renderer: function(val){
                        val = +val;
                        var day = Math.floor(val / 86400);
                        var hour = Math.floor((val % 86400) / 3600);
                        var min = Math.floor((val % 3600) / 60);
                        var sec = Math.floor(val % 60);
                        return day + "天" + hour + "小时"
                            + min + "分" + sec + "秒";
                    },
                    width: 160
                }
            ],

            store: "UserMark"
        }, { /* 武将数据 */
            xtype: "panel",
            title: "玩家武将",
            height: 250,
            frame: false,
            border: false,
            autoScroll : true,

            items: [{
                xtype: "gridpanel",
                autoHeight: true,

                columns: [
                    {header:"名称", dataIndex:'name', sortable: false, width: 150},
                    {header:"等级", dataIndex:'level'},
                    {header:"转职", dataIndex:'soldier_level'},
                    {header:"炼魂", dataIndex:'soul'},
                    {header:"神将", dataIndex:'god'},
                    {header:"战斗力", dataIndex:'fight_force'}
                ],

                store: "UserSoldier"
            }]
        }, { /* 包裹数据 */
            xtype: "panel",
            title: "玩家包裹",
            height: 300,
            frame: false,
            border: false,
            autoScroll : true,

            items: [{
                xtype: "gridpanel",
                autoHeight: true,

                columns: [
                    {header:"名称", dataIndex:'name', sortable: false, width: 150},
                    {header:"数量", dataIndex:'num'}
                ],

                store: "UserInventory"
            }]
        }]
    }]
});

function renderRed(value) {
    return "<span style='color:red;'>"+ value +"</span>";
}

function renderDate(value) {
    return new Date(+(value) * 1000).format("yyyy-MM-dd hh:mm:ss");
}
